package demo1.Assignment1;

public class GirlFriend {
    private String name;
    private Integer age;


    //定义一个变量来存储创建好的类实例
    private static GirlFriend girlFriend = null;

    //私有化构造方法，防止外部调用
    private GirlFriend(String name, Integer age) {
        this.name=name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "GirlFriend{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    //定义一个方法为程序员类提供女朋友实例
    public static GirlFriend getGirlFriend(){
        //判断存储实例是否为空
        if (girlFriend == null) {
            //如果没值，就new出一个实例，并赋值给存储实例的变量
            girlFriend = new GirlFriend("小美", 28);
        }
        return girlFriend;
    }
}

